<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  

  <script>
//     let str = 'abc';

// function strLen(str, num) {
//   let index = 0;
//     while (str.toString().length < num) {
//       str = str + '0';
//       index++;
//     }

//     console.log(str);
    
// }

// const res = strLen(str, 8);

let str = 'XSUWHQ';


// 转数组
function strLastLen(str) {
  let arr = str.split('');
    let resultLeg;
    if (arr.indexOf(' ') > 0) {
      let arrs = str.split(' ');
      resultLeg = arrs[arrs.length - 1].length;
    } else {
      resultLeg = str.length;
    }
  return resultLeg
}

const res = strLastLen(str);
console.log(res)

// console.log(res);
  </script>
</body>
</html>